#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>


int main()
{
    pid_t pid = fork();
    if(pid == 0)
    {
        //child
        
        char* const myargv[] = {
            "ls",
            "-a",
            "-l",
            NULL 
        };

        printf("before : i am a process , pid : %d, ppid : %d\n", getpid(), getppid());
        sleep(2); 
        //execl("/usr/bin/ls", "ls", "-a", "-l", NULL);
    
        // exec 带 p PATH 在PATH环境变量中找
        //execlp("ls", "ls", "-a", "-l", NULL);
        //execv("/usr/bin/ls", myargv);
        execl("./other_exe.exe", "other_exe.exe", "-a", "-b", "-c", NULL);

        exit(1);
        printf("after : i am a process , pid : %d, ppid : %d \n", getpid(), getppid());
    }
    else 
    {
        pid_t ret = waitpid(-1, NULL, 0);
        if(ret > 0)
        {
            printf("wait success! father pid : %d ret id : %d \n", getpid(), ret);
        }
    }
    return 0;
}

/*
int main()
{
    printf("before : i am a process , pid : %d, ppid : %d", getpid(), getppid());
    
    //execl("/usr/bin/ls", "ls", "-a", "-l", NULL);
    
    // exec 带 p PATH 在PATH环境变量中找
    execlp("ls", "ls", "-a", "-l", NULL);
    printf("after : i am a process , pid : %d, ppid : %d", getpid(), getppid());
    return 0;
}
*/
